package com.itlr;

public class Person {
    String name;
    int age;
    boolean gender; // true 男，false 女
    Person spouse; // 配偶

    public Person(String personName, int personAge, boolean personGender) {
        this.name = personName;
        this.age = personAge;
        this.gender = personGender;
    }

    public void marry(Person anotherPerson) {
        // 情况 1：同性
        if (this.gender == anotherPerson.gender) {
            System.out.println("不能结婚，因为是同性。");
            return;
        }

        // 情况 2：未达到结婚年龄
        boolean isThisMinor = (this.gender && this.age < 24) || (!this.gender && this.age < 22);
        boolean isAnotherPersonMinor = (anotherPerson.gender && anotherPerson.age < 24) ||
                (!anotherPerson.gender && anotherPerson.age < 22);

        if (isThisMinor || isAnotherPersonMinor) {
            System.out.println("不能结婚，因为未达到结婚年龄。");
            return;
        }

        // 情况 3：某一方已婚
        if (this.spouse != null || anotherPerson.spouse != null) {
            System.out.println("不能结婚，因为某一方已婚。");
            return;
        }

        // 可以结婚，输出恭贺信息，并设置配偶
        System.out.println(this.name + " 和 " + anotherPerson.name + " 恭喜结婚！");
        this.spouse = anotherPerson;
        anotherPerson.spouse = this;
    }

}